<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>授权操作</title>
    <script src="js/vue.min.js"></script>
    <script src="js/jquery-1.8.3.min.js"></script>
</head>
<body>
    <div id="app" style="margin: auto;margin-top: 30%;width: 100%">
        <button @click="agree" style="background-color: #1E90FF;width: 100%;height: 100px">同意授权</button></br>
        <button style="width: 100%;height: 100px">取消授权</button>
    </div>
</body>
</html>
<script>
    new Vue({
        el: '#app',
        data: {
            platform: "pc",
            token: ""
        },
        created: function () {
            this.getToken();
            //用户扫描二维码后,跳转该页面,该登陆授权页面渲染前,拼接所需参数
            this.platform = "pc";
            //调用接口告诉扫描二维码页面,用户已经扫描了二维码,处理等待用户同意授权阶段 (扫描成功,请在手机端授权操作)
            this.sendWsMsg();
        },
        methods: {
            agree() {
                //===========模拟获取用户信息token===============
                this.getToken();
                //===========模拟获取用户信息token===============
                $.ajax({
                    url: 'http://210.22.22.150:3930/qrCode/agree?platform=' + this.platform + '&token=' + this.token,
                    type: "GET",
                    dataType: 'json',
                    async: false,
                    success: function (res) {
                        if (res.success) {
                            window.location.href = res.url;
                        } else {
                            alert(res.msg)
                        }
                    },
                    error: function (res) {
                        console.log('网络开了小差，请稍后再试！');
                    }
                });
            },
            getToken() {
                let _this = this;
                $.ajax({
                    url: 'http://210.22.22.150:3930/qrCode/generateJwt?mobile=18333333333',
                    type: "GET",
                    dataType: 'json',
                    async: false,
                    success: function (res) {
                        if (res.success) {
                            _this.token = res.token;
                        }
                    }
                });
            },
            sendWsMsg() {
                let _this = this;
                $.ajax({
                    url: 'http://210.22.22.150:3930//qrCodeWs/sendUser?token='+ _this.token,
                    type: "GET",
                    dataType: 'json',
                    async: false,
                    success: function (res) {
                        console.log("res|" + res.msg)
                    }
                });
            }
        }
    })
</script>